<template>
  <Nav :showBlack="true" :title="dec_data.name"></Nav>
  <div class="page" v-if="ready == 1">
    <div class="spreen" v-if="ready == 0"></div>
    <div class="lookBox" v-if="dec_data.type == 1">
      <img src="../assets/rote.png" class="rote" alt="">
      <vue3dLoader
          :filePath="dec_data.detail_dynamic_img"
          :height="height3D"
          :width="width3D"
          backgroundColor="#0f1830"
          :cameraPosition="position"
          @process="onProcess"

          :controlsOptions="{
              enablePan,
              enableZoom,
              enableRotate,
          }"
      ></vue3dLoader>
    </div>
    <div class="lookBox2" v-if="dec_data.type == 2">
       <img :src="dec_data.detail_dynamic_img" alt="">
    </div>
<!--    :textureImage="textureImage"-->
    <div class="process" v-if="dec_data.type == 1">
      <div class="processBox" v-show="process < 100">
       <div class="processInner" :style="{width: process + '%'}"></div>
      </div>
    </div>
    <div class="itemSwiper">
      <div class="items-info">
        <div class="info-title">
          <span class="name">{{dec_data.name}}</span>
          <span>
             <img src="../assets/like.png" alt="">
             {{dec_data.is_like}}
           </span>
        </div>
<!--        <div class="f-title">-->
<!--          {{dec_data.name}}-->
<!--        </div>-->
      </div>
    </div>
    <van-tabs v-model:active="active" v-if="detail_img[0]" @click-tab="onClickTab" line-height="0" ref="tabsRef" background="#0f1830">
      <van-tab v-for="(item,index) in detail_img" :key="index">
        <template #title>
          <div class="tab-item">
            <div class="imgBox" :class="{active:active == index}" :style="{ backgroundImage: `url(${item})`}">
<!--               {{item.text}}-->
            </div>
          </div>
        </template>
      </van-tab>
    </van-tabs>
    <div class="infoBox">
      <div class="infoList">
        <div class="contrBox" @click="toggleOpen">
          <img v-show="open" src="../assets/down.png" alt="">
          <img v-show="!open" src="../assets/up.png" alt="">
        </div>
<!--        <div class="head">-->
<!--          <div class="name">{{dec_data.name}}</div>-->
<!--          <div class="spec" v-show="open">材质：</div>-->
<!--          <div class="spec" v-show="open">尺寸：</div>-->
<!--        </div>-->
        <div class="body">
          <div class="title">
            藏品介绍
          </div>
          <div class="cont" :class="{close:!open}">
            <div class="p" v-if="dec_data.descript">
              {{ removeTags(dec_data.descript)}}
            </div>
            <!--             <div class="p">它不仅是一份具有独特魅力的文化产品，更是一份能够传递文化价值和情感纽带的珍贵礼物。</div>-->
          </div>

          <div class="likeBoxWrap">
            <div class="likeBox" v-show="dec_data.is_like == 1" @click="uncollection(dec_data)">
              <!--             <img src="../assets/collect.png" alt="">-->
              <img src="../assets/collect-a.png" alt="">
              点赞藏品
            </div>
            <div class="likeBox" v-show="dec_data.is_like == 0" @click="collection(dec_data)">
              <img src="../assets/collect.png" alt="">
              <span>点赞藏品</span>
            </div>
            <a class="btn" :href="dec_data.buy_url" v-if="dec_data.buy_url">
              购买数字产品
            </a>
          </div>

        </div>
      </div>
    </div>
    <div class="dialog" v-show="dialog" @click="closeDialog">
<!--      <div class="top">-->
<!--        {{activeS}} / {{detail_img.length}}-->
<!--      </div>-->
      <div class="swiper"  @click="retrunFasle">

        <van-swipe class="dialog-swipe" :initial-swipe="activeS" :show-indicators="false">
          <template #indicator="{ active, total }">
            <div class="custom-indicator">{{ active + 1 }}/{{ total }}</div>
          </template>
          <van-swipe-item v-for="(item,index) in detail_img" :key="item">
            <div class="imgBox" :style="{ backgroundImage: `url(${item})`}"></div>
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
  </div>
</template>
<script setup>
import Nav from '@/components/nav.vue'
import vue3dLoader from '@/components/3dLoader/vue3dLoader.vue'
import { modelDate } from '@/utils/utils.js'

import {api} from "@/utils/api.js";
import { useRoute } from 'vue-router'
import {ref, onMounted, reactive} from 'vue';
import { removeTags } from "@/utils/utils.js";
import { showToast } from "vant";
const position = ref({ x: 0, y: 0, z: 0});

const process = ref(0);
const enablePan = ref(false);
const enableZoom = ref(false);
const enableRotate = ref(true);
const detail_img = ref([]);
const ready = ref(0);
const dialog = ref(true);
const route = useRoute();

const width3D = window.innerWidth / 1080 * 980
const height3D = window.innerWidth / 1080 * 700
const open = ref(false)
const active = ref(0);
const activeS = ref(2);
const tabsRef = ref();

let url3D = ref('')
let dec_data = ref({})
let coll_data = reactive([]);

const lights = ref();
lights.value = [
  {
    type: "AmbientLight",
    color: "white",
  },
  // {
  //   type: "DirectionalLight",
  //   position: { x: 100, y: 10, z: 100 },
  //   color: "white",
  //   intensity: 0.1,
  // }
  {
    type: "PointLight",
    color: "white",
    position: { x:30, y:-50, z:0 },
    intensity: 0.1
  }
  // {
  //   type: "HemisphereLight",
  //   skyColor: "white",
  //   groundColor: "#000000",
  //   position: { x: 200, y: -200, z: 100 }
  // }
];

onMounted(() => {
  render();
})


async function render() {
  const res = await api('/api/collectiondetail/collection_detail','post',{id:route.query.id})

  dec_data.value = res;
  detail_img.value = res.detail_img.split(',');
  console.log(res)
  console.log(dec_data.value);
  ready.value = 1;
  dialog.value = false;
}

async function collection (item) {
  const res = await api('/api/collectiondetail/collection_detail_like','post',{id:route.query.id})
  //console.log(res);
  if(Array.isArray(res)) {
    item.is_like = 1;
    item.like_count ++;
    showToast('点赞成功');
  }
}

async function uncollection (item) {
  const res = await api('/api/collectiondetail/collection_detail_cancle_like','post',{id:route.query.id})
  //console.log(res);
  if(Array.isArray(res)) {
    item.is_like = 0
    item.like_count --;
    showToast('取消点赞成功');
  }
}


function onProcess(event) {
  process.value = Math.floor((event.loaded / event.total) * 100);
}

const onClickTab = (item) => {
  // url3D.value = coll_data[item.name].model;
  // position.value = coll_data[item.name].position;
  // console.log(active.value)
  activeS.value = active.value;
  dialog.value = true;
};

const toggleOpen = () => {
  open.value = !open.value;
}

const closeDialog = () =>{
  dialog.value = false;
}

const retrunFasle = (e) => {
  // alert(123)
  e.stopPropagation()
}

</script>
<style scoped lang="scss">
@import '@/assets/style/mixin';
.dialog {
  position: fixed;
  left:0;
  right:0;
  top:0;
  bottom:0;
  background: #000;
  z-index: 99;
  display: flex;
  justify-content: center;
  align-items: center;
  //.top {
  //  position: absolute;
  //  top:300px;
  //  left:0;
  //  right: 0;
  //  text-align: center;
  //}
  .swiper {
      padding-top: 155px;
  }
  .dialog-swipe {
    .van-swipe__indicators {
      display: none;
    }
    width: 100vw;
    .imgBox {
      width: 100vw;
      height: 1200px;
    }
  }
}

:deep(.van-tab--grow) {
  padding: 0 5px;
}
:deep(.van-tabs--line .van-tabs__wrap) {
  height: auto;
}
.spreen {
  height: 1200px;
}
.tab-item {
  width: 240px;
  height: 240px;
  //border:1px solid #ddd;
  padding: 10px;
  .imgBox {
    width: 100%;
    height: 100%;
    //background-color:pink;
    color:#fff;
    @include  center();
    &.active {
      transform: scale(1.1);
    }
  }
}
.page {
  background: #0f1830;
  padding-top: 170px;
  padding-bottom: 200px;
  color:#fff;
}
.likeBoxWrap {
  display: flex;
  justify-content: center;
  .btn {
    height: 100px;
    padding: 0 30px;
    background: #cf5d27;
    color:#fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    border-radius: 10px;
    margin-left: 90px;
  }
}
.lookBox {
  display: flex;
  padding: 30px 0 45px 0;
  position: relative;
  margin-bottom: 50px;
  @include center();
  .rote {
    position: absolute;
    left:460px;
    top:700px;
    width: 180px;
  }
}
.lookBox2 {
  height: 1000px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
  img {
    max-width: 100%;
    max-height: 100%;
  }
}
.process {
  padding: 10px 0px 30px 35px;
  height: 60px;
  .processBox {
    width: 990px;
    height: 9PX;
    border:1PX solid #f6f0e6;
    box-sizing: border-box;
    .processInner {
      //width:100%;
      height: 8PX;
      background: #f6f0e6;
    }
  }
}
.main-info {
  width: 100%;
  padding:0 58px;
  background: #0a0f18;
  .imgBox {
    width: 100%;
    height: 722px;
    border-radius: 24px;
    margin-bottom: 50px;
  }
}
.nameBox {
  display: flex;
  justify-content: space-between;
  height: 90px;
  .name {
    font-size: 46px;
  }
  .control {
    display: flex;
    justify-content: space-between;
    height: 90px;
    > div {
      margin-left: 40px;
      font-size: 40px;
      img {
        height: 40px;
        width: auto;
        margin-right:10px;
        vertical-align: text-bottom;
      }
    }
  }
}
.tags {
  overflow: hidden;
  margin-bottom: 20px;
  .tag {
    float: left;
    font-size:32px;
    background: #f4eacf;
    color:#040810;
    font-weight: bold;
    padding: 10px 16px;
    border-radius: 10px;
    margin-right: 20px;
  }
}
.info {
  font-size: 36px;
  line-height: 2;
  margin-bottom: 20px;
}

.controlBox {
  border:3PX solid #f4eacf;
  border-radius: 20px;
  padding: 42px 0;
  display: flex;
  margin-bottom: 40px;
  .cont {
    flex: 1;
    height: 30px;
    font-size: 36px;
    color:#f4eacf;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1.6;
    img {
      margin-right: 16px;
      height: 50px;
    }
    &.border {
      border-right: 3PX solid #f4eacf;
    }
  }
}
.itemSwiper {
  padding: 0  50px;
  .s-title {
    display: flex;
    justify-content: space-between;
    font-size: 38px;
    margin-bottom: 80px;
  }
  .swiperBox {
    display: flex;
    margin-right: -30px;
    margin-left: -30px;
    margin-bottom: 46px;
    .leftBr {
      flex:1;
      height: 873px;
      @include center();
      img {
        width: 76px;
        height: 76px;
      }
    }
    .rightBr {
      flex:1;
      height: 873px;
      @include center();
      img {
        width: 76px;
        height: 76px;
      }
    }
    .inner {
      width: 680px;
      height: 873px;
      flex:none;
      background: pink;
    }
  }
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
  height: 873px;
}
.items-info {
  .info-title {
    font-size: 40px;
    margin-bottom: 50px;
    img {
      width: 42px;
    }
    .name {
      font-size: 46px;
      margin-right: 42px;
    }
    @include center();
  }
  .f-title {
    font-size: 40px;
    margin-bottom: 60px;
    @include center();
  }
  .btns {
    margin-bottom: 60px;
    @include center();
    .btn {
      font-size: 40px;
      padding: 25px;
      border:3px solid #fff;
      width: 320px;
      border-radius: 15px;
      @include center()
    }
  }
}
.van-swipe-item {
  display: flex;

  @include center();
}
.imgBoxInner {
  width: 80%;
  height: 80%;
  background: pink;
  border-radius: 14px;
  &.big {
    width: 94%;
    height: 94%;
  }
}
.courseBlock {
  padding: 42px 58px;
  .head {
    font-size: 46px;
    margin-bottom: 60px;
  }
}

.item {
  border:1px solid #484a4a;
  border-radius: 34px;
  padding: 40px;
  margin-bottom: 40px;
  display: flex;
  .imgbox {
    width: 146px;
    height: 146px;
    border-radius:15px;
    background-color: #b3aa9a;
    flex: none;
  }
  .infoBox {
    margin-left: 40px;
    .info-title {
      font-size: 46px;
      margin-bottom: 15px;
    }
    .info-minTitle {
      font-size: 32px;
      line-height: 1.3;
      @include ellipsis2(2)
    }
  }
}
.infoBox {
  padding-top: 44px;
  padding-left: 64px;
  padding-right:64px;
  .infoList {
    width: 100%;
    background: #f6f0e6;
    padding: 40px;
    border-radius: 40px;
    font-weight: bold;
    position: relative;
    .contrBox {
      position: absolute;
      right:0;
      top:0px;
      width: 100px;
      height: 100px;
      img{
        width: 50px;
        height: 50px;
      }
      @include center();
    }
    .head {
      color:#050911;
      font-size: 46px;
      margin-bottom: 20px;
      .name {
        margin-bottom: 20px;
      }
      .spec {
        font-size: 32px;
        margin-bottom: 12px;
      }

    }
    .body {
      .title {
        color:#040810;
        font-size: 34px;
        margin-bottom: 20px;
        font-weight: bold;
        padding-top: 20px;
      }
      .cont {
        margin-bottom: 30px;
        &.close {
          height: 96px;
          overflow: hidden;
        }
      }
      .p {
        font-size: 32px;
        color:#040810;
        line-height: 1.6;
      }

    }
  }
  .likeBox {
    height: 100px;
    color:#040810;
    font-size: 46px;
    img {
      height: 50px;
      margin-right: 10px;
    }
    @include center();
  }
}
</style>
